package com.zj.juc.study.addr;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.LongAdder;

/**
 * @author 自己的名字
 * @version 1.0.0
 * @ClassName LonAddrDemo
 * @Description LongAdder
 * @createTime 2025年01月03日 21:17
 */
public class LonAddrDemo {

    public static void main(String[] args) {
        LongAdder longAdder = new LongAdder();

        for (int i = 0; i < 50; i++) {
            new Thread(()->{
                for (int j = 0; j < 10_00_00; j++) {
                    longAdder.increment();
                }
            },"thread-"+i).start();
        }
        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(longAdder.sum());
    }
}
